package com.atguigu.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.atguigu.base.BaseMapper;
import com.atguigu.base.BaseServiceImpl;
import com.atguigu.entity.Community;
import com.atguigu.mapper.CommunityMapper;
import com.atguigu.mapper.DictMapper;
import com.atguigu.service.CommunityService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

@Service
public class CommunityServiceImpl extends BaseServiceImpl<Community> implements CommunityService {
    @Autowired
    private CommunityMapper communityMapper;
    @Autowired
    private DictMapper dictMapper;
    @Override
    public BaseMapper<Community> getBaseMapper() {
        return communityMapper;
    }

    @Override
    public PageInfo<Community> findPage(Map<String,Object> filters) {
        PageInfo<Community> page = super.findPage(filters);
        List<Community> pageList = page.getList();
        for (Community community : pageList) {
            //根据areaId获取areaName
            String areaName = dictMapper.getNameById(community.getAreaId());
            community.setAreaName(areaName);
            //根据plateId获取plateName
            String plateName = dictMapper.getNameById(community.getPlateId());
            community.setPlateName(plateName);
        }

        return page;
    }

    @Override
    public List<Community> findAll() {
        return communityMapper.findAll();
    }

    @Override
    public Community getById(Long id) {
        Community community = communityMapper.getById(id);
        community.setAreaName(dictMapper.getNameById(community.getAreaId()));
        community.setPlateName(dictMapper.getNameById(community.getPlateId()));
        return community;
    }
}